package com.trustasia.hibernate.dao.impl;

import com.trustasia.hibernate.dao.IUserDao;
import com.trustasia.hibernate.pojo.Users;

public class UserDaoImpl extends GenericDaoImpl<Users, Integer> implements IUserDao
{
    
    public void add(Users user)
    {
        this.save(user);
    }
    
    public Users findUserByLogname(String loginname)
    {
        String hql = new StringBuffer()
                  .append("select u ")
                  .append("from Users u ")
                  .append("where loginname=?")
                  .toString();
        return (Users)this.findObject(hql, loginname);
    }

    /**
     * 重写方法
     * @param id
     * @return
     * @see com.itany.net.dao.IUserDao#findUserById(java.lang.Integer)
     */
    public Users findUserById(Integer id)
    {
        StringBuffer hql=new StringBuffer()
                        .append("select u ")
                        .append("from Users u ")
                        .append("where u.id=?");
        return (Users)this.findObject(hql.toString(), id);
    }

    public void updateUserInfo(Users user)
    {
        this.update(user);
    }

    public Users getUserByPwdId(Integer id, String password)
    {
        StringBuffer hql=new StringBuffer()
                        .append("select u ")
                        .append("from Users u ")
                        .append("where u.id=? ")
                        .append("and u.loginpassword=?");
        return (Users)this.findObject(hql.toString(), id,password);
    }

    public void deleteUserById(Integer id)
    {
        this.deleteById(id);
    }

	public Users findUserBylogin(String username, String password) {
		 StringBuffer hql=new StringBuffer()
         .append("select u ")
         .append("from Users u ")
         .append("where u.loginname=? ")
         .append("and u.loginpassword=?");
		 return (Users)this.findObject(hql.toString(), username,password);
		
	}
    
}
